<?php

/**
 * This is the model class for table "tbl_member".
 *
 * The followings are the available columns in table 'tbl_member':
 * @property integer $member_id
 * @property string $username
 * @property string $password
 * @property string $email
 * @property integer $connection_count
 * @property string $about
 * @property string $nickname
 * @property string $img_profile
 * 
 * The followings are the available model relations:
 * @property TblActivitys[] $tblActivitys
 * @property TblConnections[] $tblConnections
 * @property TblConnections[] $tblConnections1
 * @property TblGroupMembers[] $tblGroupMembers
 * @property TblMembeSkills[] $tblMembeSkills
 * @property TblMemberIdioms[] $tblMemberIdioms
 * @property TblMemberInterrest[] $tblMemberInterrests
 * @property TblMemberProfileWorkersSchoolTimeline[] $tblMemberProfileWorkersSchoolTimelines
 * @property TblMemberUrl[] $tblMemberUrls
 * @property TblMessages[] $tblMessages
 * @property TblMessages[] $tblMessages1
 */
class Members extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Members the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tbl_member';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('username, password, email', 'required'),
			array('connection_count', 'numerical', 'integerOnly'=>true),
			array('username, password, email', 'length', 'max'=>128),
			array('about', 'safe'),
                        array('nickname', 'length', 'max'=>80),
                    
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('member_id, username, password, email, connection_count, about', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'tblActivitys' => array(self::HAS_MANY, 'TblActivitys', 'member_id'),
                    'activitysCount'=>array(self::STAT, 'Activitys', 'member_id'),
                    
			'tblConnections' => array(self::HAS_MANY, 'TblConnections', 'friendship_id'),
			'tblConnections1' => array(self::HAS_MANY, 'TblConnections', 'member_id'),
			'tblGroupMembers' => array(self::HAS_MANY, 'TblGroupMembers', 'member_id'),
			'tblMembeSkills' => array(self::HAS_MANY, 'TblMembeSkills', 'member_id'),
			'tblMemberIdioms' => array(self::HAS_MANY, 'TblMemberIdioms', 'member_id'),
			'tblMemberInterrests' => array(self::HAS_MANY, 'TblMemberInterrest', 'member_id'),
			'tblMemberProfileWorkersSchoolTimelines' => array(self::HAS_MANY, 'TblMemberProfileWorkersSchoolTimeline', 'member_id'),
			'tblMemberUrls' => array(self::HAS_MANY, 'TblMemberUrl', 'member_id'),
			'tblMessages' => array(self::HAS_MANY, 'TblMessages', 'sender_id'),
			'tblMessages1' => array(self::HAS_MANY, 'TblMessages', 'recipient_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'member_id' => 'Member',
			'username' => 'Username',
			'password' => 'Password',
			'email' => 'Email',
			'connection_count' => 'Connection Count',
			'about' => 'About',
                        'nickname' => 'nickname',
                        'img_profile'=>'img_profile',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('member_id',$this->member_id);
		$criteria->compare('username',$this->username,true);
		$criteria->compare('password',$this->password,true);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('connection_count',$this->connection_count);
		$criteria->compare('about',$this->about,true);
                $criteria->compare('nickname',$this->nickname,true);
                $criteria->compare('img_profile',$this->img_profile,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}